package com.kandinfo.base.admin.repository;

import java.util.List;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.Query;

import com.kandinfo.base.admin.constant.CacheConstant;
import com.kandinfo.base.admin.domain.DictData;
import com.kandinfo.base.common.repository.BaseRepository;


/**
 * 基础字典类
 * 
 * @author wenchongyang
 *
 */
public interface DictDataRepository extends BaseRepository<DictData, Long> {
    @Query(value = "SELECT dd FROM DictData dd ,DictDef ddf WHERE dd.dictDefId=ddf.id  and ddf.code=?1 order by dd.index")
    @Cacheable(value = CacheConstant.DICT_CACHE)
    List<DictData> getByRef(String code);

    @Query(value = "select da.value from dict_data da,dict_def df where da.dict_def_id=df.id and da.code=?1 and df.code=?2 limit 1", nativeQuery = true)
    @Cacheable(value = CacheConstant.DICT_CACHE)
    String getByCodeAndDefCode(int id, String code);

    @Query(value = "SELECT dd FROM DictData dd ,DictDef ddf WHERE dd.dictDefId=ddf.id  and ddf.code=?1 order by dd.index")
    @Cacheable(value = CacheConstant.DICT_CACHE)
    List<DictData> getByCode(String code);
}
